import 'package:fate_blind_box/network/http_config.dart';
import 'package:flutter/foundation.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_proxy/shelf_proxy.dart';

//前端页面访问本地域名
const String _localHost = 'localhost';

//前端页面访问本地端口号
const int _localPort = 8080;

//目标域名，这里我们将要请求火狐的这个地址
const String _targetUrl = HttpConfig.baseUrlProxy;


Future main() async {
  var server = await shelf_io.serve(
    proxyHandler(_targetUrl),
    _localHost,
    _localPort,
  );
  server.defaultResponseHeaders.add('Access-Control-Allow-Origin', '*');
  server.defaultResponseHeaders.add('Access-Control-Allow-Credentials', true);
  server.defaultResponseHeaders.add('Access-Control-Allow-Methods', '*');
  server.defaultResponseHeaders.add('Access-Control-Allow-Headers', '*');
  server.defaultResponseHeaders.add('Access-Control-Max-Age', '3600');

  if (kDebugMode) {
    print('Serving at http://${server.address.host}:${server.port}');
  }
}